package cn.com.nes.site.action.monitor;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.monitor.ParamService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("param")
@RequestMapping("/param")
public class ParamAction {

    @Resource
    private ParamService service;

    @RequestMapping(method = RequestMethod.POST, value = "/addCustomParam")
    @ResponseBody
    public PageData addCustomParam(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.addCustomParam(reqStatus.getReq());
        return res;
    }

    @RequestMapping(method = RequestMethod.GET, value = "/getCustomParams")
    @ResponseBody
    public PageData getCustomParams(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.getCustomParams(reqStatus.getReq());
        return res;
    }

    /**
     * 删除预警规则   可批量
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/deleteCustomParams")
    @ResponseBody
    public PageData deleteCustomParams(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.deleteCustomParams(reqStatus.getReq());
        return res;
    }

}
